
const iotClient =  require("./iotClient")
const par = require("./param")
const deviceConf = require("./deviceConf.json")

function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}


async function main() {

    await iotClient.connect(deviceConf.deviceList)
    for (device of deviceConf.deviceList) {
        let client = iotClient.deviceClients[device.dn]
        for (let parlist of [par.getBaseParam(), par.getSeasonPrarm(), par.getRemindPrarm(), par.getWokUpkeepSettingParam(), par.getIngrUpkeepSettingParam(), par.getOtherSettingParam()]) {
            let dataArray = []
            for (const param of parlist) {
                dataArray.push({
                    eventName:  "deviceParamUpdate",
                    data: {
                        "content":{
                            "cgid": device.cgid,
                            "deviceAlias": device.deviceAlias,
                            "pk": device.pk,
                            "productName": device.pn,
                            "merchantId": deviceConf.bindMerchantId,
                            "merchantName": deviceConf.bindMerchantName,
                            "storeId": deviceConf.bindStoreId,
                            "storeName": deviceConf.bindStoreName,
                            // "paramTmplGroupId": 0,
                            // "paramTmplId": 0,
                            "settingWay": 0,
                            "updateUserUuid": deviceConf.bindUserUid,
                            "updateTime": Date.now(),
                            ...param,
                        }
                    }
                })
            }
            await delay(500)
            console.log(client.model.deviceName + "：上报设备参数")
            client.postEvent('generalEvent', body = {dataArray: dataArray}, (res)=>{
                console.log(client.model.deviceName + "：上报设备参数结果：" + JSON.stringify(res))

            });
        }
    }
}

main()